<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Card extends CI_Controller {
	/**
	 * Contrust class
	 *
	 * @access public
	 */
     
    //Mang tham so nhan duoc o moi action
    protected $_arrParam;
     
	public function __construct(){
		parent::__construct();
        require_once(APPPATH . 'modules/backend/autoload.php');
		$this->load->library('login_manager');
        $this->load->model('kpay/db_card_model');
		$this->load->language('backend');
		$this->smarty->assign('language', $this->lang);
		$this->smarty->assign('message',$this->session->flashdata('message'));
		$this->smarty->assign('error_message',$this->session->flashdata('error_message'));
        
        $jqxtheme = array(base_url() . 'library/jqwidgets/styles/jqx.darkblue.css');
        $css_files = array(base_url() . 'jscripts/jqxGrid/styles/jqx.base.css');

        $js_files = array(
                base_url() . 'jscripts/jqxGrid/jqx-all.js'
        );
        $this->smarty->assign('jqxtheme', $jqxtheme);
        $this->smarty->assign('css_files', $css_files);
        $this->smarty->assign('js_files', $js_files);
        
        require_once(APPPATH . 'modules/backend/denied.php');
        
	}
	
	function index(){
        $this->smarty->assign('title', __METHOD__);
        $card = $this->db_card_model->getCards();print_r($card);
        
        //$this->smarty->view('backend/card/jqxgrid', 'grid');
        $this->smarty->display('backend/admin');
	}
	
    public function categories(){
        $this->smarty->assign('title', 'Admin Panel - Danh mục thẻ');
        $this->smarty->assign('heading', 'DANH MỤC THẺ');
        $jqxgrid = array();
        $jqxgrid['url_metadata'] = base_url().($this->router->directory.'card/categories');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/jqx_categories');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/card/categories', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục thẻ",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function provider(){
        $this->smarty->assign('title', 'Admin Panel - Danh mục nhà cung cấp');
        $this->smarty->assign('heading', 'DANH MỤC NHÀ CUNG CẤP');
        $jqxgrid = array();
        $jqxgrid['url_metadata'] = base_url().($this->router->directory.'card/provider');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/jqx_provider');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/card/provider', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục nhà cung cấp",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function product(){
        $this->smarty->assign('title','Admin Panel - Danh mục sản phẩm');
        $this->smarty->assign('heading','DANH MỤC SẢN PHẨM');
        $jqxgrid = array();
        $jqxgrid['url_metadata'] = base_url().($this->router->directory.'card/product');
        $jqxgrid_init = $this->smarty->get_contents('backend/js/jqx_product');
        $js_text = array($jqxgrid_init);
        $this->smarty->assign('js_text', $js_text);
        
        $this->smarty->view('backend/card/product', 'grid');
        $this->smarty->display('backend/admin');
        
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục sản phẩm",
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
	
	function jqxgrid_json_product(){ // Data Json cardproduct
		if(IS_AJAX){
			$result['rows'] = $this->db_card_model->CardProduct($this->_arrParam, array('task'=>'product-list'));
                        $result['total_row'] = count($result['rows']);
			echo json_encode($result);
		}
	}
    
    function jqxgrid_json_cat(){ // Data Json cardcategoris
		if(IS_AJAX){
			$result['rows'] = $this->db_card_model->CardCategoris($this->_arrParam, array('task'=>'cat-list'));
                        $result['total_row'] = count($result['rows']);
			echo json_encode($result);
		}
	}
    
    function jqxgrid_json_provider(){ // Data Json cardproviders
		if(IS_AJAX){
			$result['rows'] = $this->db_card_model->CardProvider($this->_arrParam, array('task'=>'provider-list'));
                        $result['total_row'] = count($result['rows']);
			echo json_encode($result);
		}
	}
    
    public function update_product(){ // Change Status: cardproducts
        $this->db_card_model->CardProduct($this->_arrParam, array('task'=>'product-update'));
        $userlog = $this->db_user_model->getCardProduct($this->_arrParam['productID']);
        foreach($userlog as $value){
            $productID = $value->productName;
        }
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục sản phẩm : ".$productID.", Status = ".$this->_arrParam['status'],
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function update_cat(){ // Change Status: cardcategoris
        $this->db_card_model->CardCategoris($this->_arrParam, array('task'=>'cat-update'));
        $userlog = $this->db_user_model->getCardCategorie($this->_arrParam['catID']);
        foreach($userlog as $value){
            $catID = $value->catName;
        }
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục thẻ: ".$catID.", Status = ".$this->_arrParam['status'],
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
    
    public function update_provider(){ // Change Status: cardproviders
        $this->db_card_model->CardProvider($this->_arrParam, array('task'=>'provider-update'));
        $userlog = $this->db_user_model->getCardProvider($this->_arrParam['providerID']);
        foreach($userlog as $value){
            $providerID = $value->providerName;
        }
        $user = $this->login_manager->get_user();
        $aParamAdminLog=array(
                        'username'   => $user[0]->name,
                        'customerID' => $user[0]->customerID,
                        'email'      => $user[0]->email,
                        'lastLogin'  => date("Y-m-d H:i:s"),
                        'logAction'  => "Quản lý thông tin thẻ : Danh mục nhà cung cấp: ".$providerID.", Status = ".$this->_arrParam['status'],
                        'ip'         => $_SERVER['REMOTE_ADDR'],
                        'uID'        => $user[0]->uID
                        );
        $log = $this->db_user_model->insertUserAdminLog($aParamAdminLog);
    }
}



	
/* End of file user.php */
/* Location: ./system/application/controllers/backend/card.php */